package com.mpaster.webfluxdemo.configure;

import com.mpaster.webfluxdemo.controller.TimeHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.*;

@Configuration
public class RouteConfig {

    @Autowired
    private TimeHandler timeHandler;

    @Bean
    public RouterFunction<ServerResponse> timerRouter(){
        return RouterFunctions.route(RequestPredicates.GET("/time"), request -> timeHandler.getTime(request))
                .andRoute(RequestPredicates.GET("/date"), timeHandler::getDate)
                .andRoute(RequestPredicates.GET("/times"), timeHandler::sendTimePerSec); // 这样更简洁
    }
}
